package com.googlecode.maratische.google.gui;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;

/**
 * Показываем окно, подтверждающие пометку статьи
 * @author gizatullinm
 *
 */
public class InfWindowShowMessage extends InfWindowAddOfflineMode {

	private static final long serialVersionUID = 1382030429306803892L;
	private JButton btnClose = new JButton("Close");
	
	public InfWindowShowMessage(Point parentPosition, Dimension parentSize, String message, Integer time) {
		super(parentPosition, parentSize);
		init(message);
		
		timerPosition = time;
		timer.start();
	}

	
	public void init(String message) {
		
		setLayout(new FlowLayout());
		StringBuilder name = new StringBuilder("<html>");
		name.append(message);
		name.append("</html>");
		JLabel label = new JLabel(name.toString());
		label.setToolTipText(name.toString());
		add(label);
		add(btnClose);
		btnClose.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				InfWindowShowMessage.this.dispose();
			}
		});
	}

	@Override
	public void actionPerformed(ActionEvent e) {
//		logger.info("tick! ");
		if (timerPosition < 1) {
			timer.stop();
//			logger.info("timer STOP! ");
			timer.removeActionListener(this);
			close();
			return;
		}
		btnClose.setText("Close ("+ timerPosition-- + ")");
	}
	
}
